package com.yn.pet.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 分类枚举，对应图一的各类别信息
 */
@Getter
@AllArgsConstructor
public enum PetTypeEnum {

    // 交通工具相关
    CAR(1, "汽车"),
    TRUCK(2, "货车"),
    ELECTRIC_VEHICLE(3, "电动车"),
    MOTORCYCLE(4, "摩托车"),
    SHIP(5, "轮船"),

    // 人物相关
    MAN(6, "男人"),
    WOMAN(7, "女人"),

    // 其他物品/动物等
    DRONE(8, "无人机"),
    CAT(9, "猫"),
    DOG(10, "狗"),
    SHEEP(11, "羊"),
    COW(12, "牛");

    private final Integer code;
    private final String name;

    /**
     * 根据编码获取枚举实例
     * @param code 编码
     * @return 对应的枚举实例，无匹配时返回 null
     */
    public static PetTypeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (PetTypeEnum enumObj : PetTypeEnum.values()) {
            if (enumObj.getCode().equals(code)) {
                return enumObj;
            }
        }
        return null;
    }

    public static String getNameByCode(Integer code) {
        PetTypeEnum petTypeEnum = getByCode(code);
        return petTypeEnum == null ? null : petTypeEnum.getName();
    }
}